package com.zs.service.impl.common;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.mzt.logapi.beans.LogRecord;
import com.mzt.logapi.service.ILogRecordService;
import com.zs.common.model.common.LogRecordEntity;
import com.zs.dao.repository.common.LogRecordRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Copyright 2022 ZS Network Co., Ltd. All rights reserved.
 * 本文件仅限于正数网络技术有限公司内部传阅，禁止外泄以及用于其他的商业目的。
 * Created by 张晓珂 on 2022/3/23.
 *
 * @description:
 */
@Service
@Slf4j
public class LogRecordDbService implements ILogRecordService {

    @Value("${logRecord.db:false}")
    private boolean logRecordDbSwitch;
    @Autowired
    private LogRecordRepository logRecordRepository;

    @Override
    public void record(LogRecord logRecord) {
        log.info("log record：{}", JSONObject.toJSONString(logRecord, SerializerFeature.WriteMapNullValue));
        if(logRecordDbSwitch){
            logRecordRepository.save(LogRecordEntity.from(logRecord));
        }
    }

    @Deprecated
    @Override
    public List<LogRecord> queryLog(String bizNo, String type) {
        return null;
    }

    @Deprecated
    @Override
    public List<LogRecord> queryLogByBizNo(String bizNo, String type, String subType) {
        return null;
    }
}
